<?php

/** 
* 
* 
* by:南宁火蝶科技有限公司 http:///www.HdsysCms.com
* 声明:本系统禁止用二次开发、侵犯HdsysCms著作和除去HdsysCms进行售卖,如发现将追究一切权利,模版制作属于自己所得可以通过本系统对外开发模版获取收益!
* 
* 2019年第一版本发布 - 到2023.9.1开源使用! 
* php混淆工具:phpencry.wbox.top
* 
* 注意防骗:@HdsysCms 官方没授权任何个人机构合作,唯一收款抬头:《南宁火蝶科技有限公司》和官网显示客服唯一渠道客服,其它渠道以HdsysCms名义行为均骗子!
*
*/
	

function call_my_make_templates_dir($param_dir)
{
$param_templates=HDSYS_DIR_SYS . 'templates/' . $param_dir;
if (!is_dir($param_templates)) {
return false;
}
$param_templates=HDSYS_DIR_SYS . 'templates/' . $param_dir  . '/mode-josn';
if (!is_dir($param_templates)) {
@mkdir($param_templates, 0777, true);
}
$param_templates=HDSYS_DIR_SYS . 'templates/' . $param_dir  . '/modular';
if (!is_dir($param_templates)) {
@mkdir($param_templates, 0777, true);
}
$param_templates=HDSYS_DIR_SYS . 'templates/' . $param_dir  . '/statics';
if (!is_dir($param_templates)) {
@mkdir($param_templates, 0777, true);
}
$param_templates=HDSYS_DIR_SYS . 'templates/' . $param_dir  . '/statics/upfiles';
if (!is_dir($param_templates)) {
@mkdir($param_templates, 0777, true);
}
$param_templates=HDSYS_DIR_SYS . 'templates/' . $param_dir  . '/Public';
if (!is_dir($param_templates)) {
@mkdir($param_templates, 0777, true);
}
}
function call_my_is_templates($param_file)
{
$param_File_Name=HDSYS_DIR_SYS . "" . 'templates' . '/' . bs_lib::get_configs_value('template', 'current') . '/' . $param_file;
if (file_exists($param_File_Name)) {
return true;
} else {
return false;
}
}
function call_my_is_visualization($param_dir)
{
#判断正常就直接下去了
$param_url='templates/' . $param_dir . '/statics/visualization.josn';
$param_file=file_exists(HDSYS_DIR_SYS . $param_url);
if ($param_file===false) {
return (array('code'=> 3, 'msg'=> '配置文件不存在，请手动创建配置文件 Error:' . $param_url));
}
$param_file_data=file_get_contents(HDSYS_DIR_SYS . $param_url);
$param_file_josn=json_decode($param_file_data, 1);
if ($param_file_data !='' and $param_file_josn==false) {
return (array('code'=> 1, 'msg'=> '源码模式'));
}
if ($param_file_data !='' and isset($param_file_josn['visualization'])==false) {
return (array('code'=> 1, 'msg'=> '源码模式'));
}
if ($param_file_josn['visualization']==1) {
return (array('code'=> 2, 'msg'=> '可视化编辑模式'));
}
$param_file=fileperms(HDSYS_DIR_SYS . 'templates/' . $param_dir . '/statics');
if ($param_file===false) {
return (array('code'=> 3, 'msg'=> '模版配置异常 Error:模版目录异常,无非检测到statics目录,请确认存在或者读写权限正常'));
}
$param_file=fileperms(HDSYS_DIR_SYS . $param_url);
if ($param_file===false) {
return (array('code'=> 3, 'msg'=> '模版配置异常，确认存在或者文件权限 Error:' . $param_url));
}
return (array('code'=> 3, 'msg'=> '模版配置异常，未知 Error:' . $param_url));
}
function call_my_push_templates_html($param_file, $param_dir)
{
#无需生成
$param_arr=call_my_is_visualization($param_dir);
if ($param_arr['code']==1) {
return '';
}
if ($param_arr['code']==3) {
return $param_arr['msg'];
}
$param_templates=HDSYS_DIR_SYS . 'templates/' . $param_dir  . '/mode-josn';
$param_file_md5=call_my_md5($param_file);
$param_array=array('info'=> array("title"=> "", "keywords"=> "", "description"=> ""), "mode"=> array());
if (file_exists("$param_templates/$param_file_md5.josn")) {
$param_array=file_get_contents("$param_templates/$param_file_md5.josn");
if ($param_array !='') {
$param_array=json_decode($param_array, 1);
}
}
$param_mode=$param_array['mode'];
$param_description=$param_array['info']['description'];
$param_title=$param_array['info']['title'];
$param_keywords=$param_array['info']['keywords'];
$param_DIV_MEIN=(int)get_session_value('DIV_MEIN');
if ($param_DIV_MEIN==1) {
$param_mode_html='<hdsyscms-top-act>
<div class="hdsyscms-bin-show" data-dir="' . $param_dir . '"  data-file="' . $param_file . '" >可视化DIV模版:' . $param_dir . '</div>
<div class="hdsyscms-bin-seo" data-dir="' . $param_dir . '"  data-file="' . $param_file . '" >页面SEO设置</div>
<div class="hdsyscms-bin-out" data-dir="' . $param_dir . '"  data-file="' . $param_file . '" >退出可视编辑</div>
</hdsyscms-top-act>';
} else {
$param_mode_html='';
}
foreach ($param_mode as $param_v) {
if (!isset($param_v['file'])) {
$param_v['file']='';
}
$param_file_Public=HDSYS_DIR_SYS . 'templates/' . $param_dir  . '/Public/' . $param_v['file'];
$param_file_html='';
if (file_exists($param_file_Public)) {
$param_file_html=file_get_contents($param_file_Public);
}
if ($param_DIV_MEIN==1) {
$param_mode_html .='<hdsys-templates class="hdsys-templates" id="' . $param_v['id'] . '"  file="' . $param_v['file'] . '" >
<hdsyscms-code-act>
<div class="hdsyscms-bin-code" data-id="' . $param_v['id'] . '"  data-file="' . $param_v['file'] . '" >编辑源码</div>
<div class="hdsyscms-bin-age" data-id="' . $param_v['id'] . '"  data-file="' . $param_v['file'] . '" >动态标签</div>
</hdsyscms-code-act>
' . $param_file_html . ' </hdsys-templates>
';
} else {
$param_mode_html .=$param_file_html;
}
}
$param_html='<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>' . $param_title . '</title>
<meta name="keywords" content="' . $param_keywords . '" />
<meta name="description" content="' . $param_description . '" />
{$config.setup.head}
{include:link}
</head>
<body>
' . $param_mode_html . '
</body>
</html>';
$param_templates='templates/' . $param_dir . '/' . $param_file;
$param_tmp=@file_put_contents(HDSYS_DIR_SYS . $param_templates, $param_html);
if ($param_tmp) {
return '';
} else {
return  "生成模版失败<br/>目录不可写入:{$param_templates} <br/>请设置可写权限.";
}
}
function call_my_GetHdsysInfo($param_html)
{
$param_matches=array();
$intelligence_is=preg_match('/<hdsysinfo(.*?)\/>/i', $param_html, $param_matches);
if (!$intelligence_is) {
return array('name'=> '', 'info'=> '没有hdsysinfo标签', 'id'=> '');
}
$param_data=$param_matches[0];
$intelligence_is=preg_match_all('/([a-z_]+)=\"(.*?)\"/i', $param_data, $param_matches);
if (!$intelligence_is) {
return array('name'=> '', 'info'=> '', 'id'=> '');
}
$param_array=array('name'=> '', 'info'=> '', 'id'=> '');
$param_count=count($param_matches[0]);
$param_i=0;
while ($param_i < $param_count) {
$param_array[$param_matches[1][$param_i]]=$param_matches[2][$param_i];
$param_i++;
}
return $param_array;
}
function call_my_GetHdsysPage($param_html)
{
$param_matches=array();
$intelligence_is=preg_match('/<hdsyspage(.*?)\/>/i', $param_html, $param_matches);
if (!$intelligence_is) {
return array('name'=> '', 'info'=> '没有hdsyspage标签', 'id'=> '');
}
$param_data=$param_matches[0];
$intelligence_is=preg_match_all('/([a-z_]+)=\"(.*?)\"/i', $param_data, $param_matches);
if (!$intelligence_is) {
return array('name'=> '', 'info'=> '', 'id'=> '');
}
$param_array=array('name'=> '', 'info'=> '', 'id'=> '');
$param_count=count($param_matches[0]);
$param_i=0;
while ($param_i < $param_count) {
$param_array[$param_matches[1][$param_i]]=$param_matches[2][$param_i];
$param_i++;
}
return $param_array;
}
function call_my_GetDivArray($param_data)
{
$intelligence_is=preg_match_all('/([a-z_]+)=([0-9]+|[a-zA-Z0-9_$]+|\"(.*?)\"|\'.*?\')+/i', $param_data . '   ', $param_matches);
if (!$intelligence_is) {
return false;
}
$param_array=array();
$param_count=count($param_matches[0]);
$param_i=0;
while ($param_i < $param_count) {
$param_key=$param_matches[2][$param_i];
$param_key=call_my_delstr($param_key);
$param_key=call_my_str_replace('"', '\"', $param_key);
$param_key=call_my_str_basic($param_key);
$param_array[call_my_delstr($param_matches[1][$param_i])]=$param_key;
$param_i++;
}
return $param_array;
}
function call_my_GetArray($param_array, $param_data, $parem_return)
{
if (isset($param_array[$param_data])) {
if ($param_array[$param_data]=='') {
return $parem_return;
}
return $param_array[$param_data];
} else {
return $parem_return;
}
}
function call_my_var($param_data)
{
$param_v=call_my_str_replace('\$', '', $param_data);
$param_v=call_my_str_replace('$', '', $param_v);
return '$' . $param_v;
}
function call_my_echo($param_data)
{
echo $param_data;
}
function call_my_array_div($param_array)
{
if (!is_array($param_array)) {
return '';
}
$param_code_array_php=' ';
foreach ($param_array as $param_value=> $param_key) {
$param_code_array_php .=$param_value . '=\'' . $param_key . '\' ';
}
return $param_code_array_php;
}
function call_my_array_code($param_array)
{
if (!is_array($param_array)) {
return 'array()';
}
$param_code_array_php=' array<hdsyscms-kuohao> ';
$param_cum=count($param_array);
$param_i=0;
foreach ($param_array as $param_value=> $param_key) {
$param_i++;
if ($param_value=='as') {
$param_code_array_php .="\"{$param_value}\"=>'" . $param_key . "'";
} else {
$param_code_array_php .='"' . $param_value . '"=>"' . $param_key . '"';
}
if ($param_i < $param_cum) {
$param_code_array_php .=',';
}
}
$param_code_array_php .='</hdsyscms-kuohao>;';
return $param_code_array_php;
}
function call_my_delstr($param_str)
{
if (substr($param_str, 0, 1)=='"') {
return substr($param_str, 1, -1);
}
if (substr($param_str, 0, 1)=="'") {
return substr($param_str, 1, -1);
}
return $param_str;
}
function call_my_newpara($param_str)
{
if ($param_str=='') {
return '""';
}
if (substr($param_str, -1)=='(') {
return $param_str;
}
if (substr($param_str, 0, 1)=='[' and substr($param_str, -1)==']') {
return $param_str;
}
if (substr($param_str, 0, 1)=='"' and substr($param_str, -1)=='"') {
return preg_replace('#<hdsyscms-val>(.*?)</hdsyscms-val>#', '{\\1}', $param_str);
}
if (substr($param_str, 0, 1)=="'" and substr($param_str, -1)=="'") {
return '"' . preg_replace('#<hdsyscms-val>(.*?)</hdsyscms-val>#', '{\\1}', (substr($param_str, 1, -1))) . '"';
}
if (substr($param_str, 0, 1)=='$') {
return preg_replace('#<hdsyscms-val>(.*?)</hdsyscms-val>#', '{\\1}', $param_str);
}
if (substr($param_str, 0, 2)=='{$') {
return preg_replace('#<hdsyscms-val>(.*?)</hdsyscms-val>#', '{\\1}', $param_str);
}
if (substr($param_str, 0, 14)=='<hdsyscms-val>' and substr($param_str, -15)=='</hdsyscms-val>') {
return preg_replace('#<hdsyscms-val>(.*?)</hdsyscms-val>#', '\\1', $param_str);
}
if (substr($param_str, 0, 19)=='<hdsyscms-dakuohao>' and substr($param_str, -20)=='</hdsyscms-dakuohao>') {
return  '"' . preg_replace('#<hdsyscms-val>(.*?)</hdsyscms-val>#', '\\1', $param_str) . '"';
}
return '"' . $param_str . '"';
}
function call_my_str_basic($intelligence_FileTemplatescContent)
{
$patten=[
'#\{\$([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\}#',
'#\$([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)#',
'#\{@(.*?)\}#'
];
$translation=[
'<hdsyscms-dakuohao>\$\\1["\\2"]</hdsyscms-dakuohao>',
'<hdsyscms-dakuohao>\$\\1["\\2"]</hdsyscms-dakuohao>',
'<hdsyscms-dakuohao>\\1<hdsyscms-dakuohao>'
];
$intelligence_FileTemplatescContent=preg_replace($patten, $translation, $intelligence_FileTemplatescContent);
return $intelligence_FileTemplatescContent;
}
#对括号里变量进行替换成变量
function call_my_str_basic_kuohao($intelligence_FileTemplatescContent)
{
$patten=[
'#\{\$([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\}#',
'#\$([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)#',
];
$translation=[
'{\$\\1["\\2"]}',
'\$\\1["\\2"]',
];
$intelligence_FileTemplatescContent=preg_replace($patten, $translation, $intelligence_FileTemplatescContent);
return $intelligence_FileTemplatescContent;
}
#翻页循环
function call_my_page($intelligence_FileTemplatescContent, $param_jsonarr)
{
$GLOBALS['pageas']=call_my_var($param_jsonarr['pageas']);
$GLOBALS['jsonarr']=$param_jsonarr;
$intelligence_FileTemplatescContent=preg_replace_callback(
'/([{|<])page([[a-z_\s]+)=([0-9]+|[a-zA -Z0-9_]+|\"(.*?)\"|\'.*?\']+)([}|>])/i',
function ($param_matches) {
$page_array=include $this->intelligence_GetContentPageMysqlArray($param_matches[1], $GLOBALS['jsonarr']);
$GLOBALS['page_array']=$page_array;
$param_array=call_my_GetDivArray($param_matches[0]);
$param_as=call_my_var(call_my_GetArray($param_array, 'as', 'vo'));
return "<?php
{$GLOBALS['pageas']}s=(int){$page_array['pages']} + 1;
for({$param_as}['number']=1; {$param_as}['number'] < {$GLOBALS['pageas']}s; {$param_as}['number']={$param_as}['number'] + 1){ ?>";
},
$intelligence_FileTemplatescContent
);
$intelligence_FileTemplatescContent=preg_replace('#\{/page\}#', '<?php } ?>', $intelligence_FileTemplatescContent);
$intelligence_FileTemplatescContent=preg_replace_callback(
'#\{' . $GLOBALS['pageas'] . '\.([a-z_]+)\}#',
function ($param_matches) {
return $GLOBALS['page_array'][$param_matches[1]];
},
$intelligence_FileTemplatescContent
);
$intelligence_FileTemplatescContent=preg_replace_callback(
'#' . $GLOBALS['pageas'] . '\.([a-z_]+)#',
function ($param_matches) {
return $GLOBALS['page_array'][$param_matches[1]];
},
$intelligence_FileTemplatescContent
);
}
function getcdnurlhost()
{
return '//cdn.hdsyscms.com/hdsyscms/statics';
}
function call_my_get_page_list($param_v)
{
$param_d_arr=array('news'=> '文章模版', 'product'=> '产品模版','page'=> '单页模版', 'picture'=> '图片模版', 'download'=> '下载模版');
$param_File=HDSYS_DIR_SYS . 'templates/' . bs_lib::get_configs_value('template', 'current')  . '/' . $param_v . '.'  . '*.hdsys.php';
$param_File_ARRAY=glob($param_File);
$param_templates='';
foreach ($param_File_ARRAY as $param_filename) {
$param_name='';
if (preg_match('/' . $param_v . '.(.*?)\.hdsys.php/', $param_filename, $param_mac)==true) {
$param_data=@file_get_contents($param_filename);
$param_data_array=call_my_GetHdsysPage($param_data);
unset($param_data);
if ($param_data_array['name']=='') {
if (isset($param_d_arr[$param_mac[1]])) {
$param_name=$param_d_arr[$param_mac[1]];
} else {
$param_name=$param_mac[1] . ' (未命名模版)';
}
} else {
$param_name=$param_data_array['name'];
}
$param_templates .='<option value="' . $param_mac[1] . '">' . $param_name . '</option>';
}
}
return $param_templates;
}
